<?php
// 简单的团队预约API调试脚本
header('Content-Type: application/json; charset=utf-8');

require_once '../config/database.php';

try {
    $pdo = new PDO(
        'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET,
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ]
    );
    
    echo "数据库连接成功\n";
    
    // 检查数据
    $stmt = $pdo->query("SELECT COUNT(*) as count FROM team_reservations");
    $count = $stmt->fetch()['count'];
    echo "数据库中有 {$count} 条团队预约记录\n";
    
    if ($count > 0) {
        // 获取所有数据
        $stmt = $pdo->query("SELECT * FROM team_reservations ORDER BY created_at DESC");
        $reservations = $stmt->fetchAll();
        
        echo "\n团队预约数据:\n";
        echo json_encode($reservations, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
}
?>